package com.webbei.shoppingCar.action;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Random;

import org.apache.struts2.ServletActionContext;

import sun.misc.BASE64Decoder;

public class getImageByData {
	private String imgStr;
	private String filename;

	public String execute() {
		if (imgStr == null) return "false";
		BASE64Decoder decoder = new BASE64Decoder();
		try {
			byte[] b = decoder.decodeBuffer(imgStr);
			String path=ServletActionContext.getServletContext().getRealPath("/");
			filename = "temp/" + String.valueOf((new Date().getTime())) + String.valueOf(new Random().nextInt(3)) + ".png";
			OutputStream out = new FileOutputStream(path+filename);
			out.write(b);
			out.flush();
			out.close();
			return "success";
		} catch (Exception e) {
			return "false";
		}
	}


	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}


	public String getImgStr() {
		return imgStr;
	}


	public void setImgStr(String imgStr) {
		this.imgStr = imgStr;
	}



}
